package de.koller.zero.view;

import de.koller.zero.ZeroRoot;
import de.koller.zero.arch.ZNode;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;

abstract public class ZFrameNode extends ZNode {
	
	protected final JFrame frame = new JFrame();

	@Override
	public void generate( ZeroRoot root, Object... references ) {
		super.generate( root, references );
		
		frame.setTitle( this.getTitle() );
		frame.setBounds( getLocation() );
		
		frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );
		frame.setResizable( false );
			
		frame.addWindowListener( new WindowAdapter() {
			@Override public void windowClosing( WindowEvent e ) {
				ZFrameNode.this.frameClosed();
			}
		} );
			
		frame.setType( this.getFrameType() );
		frame.setVisible( true );
	}

	@Override
	public void ungenerate() {
		super.ungenerate();
		
		frame.dispose();
	}
	
	protected Window.Type getFrameType() {
		return Window.Type.UTILITY;
	}
	
	abstract protected String getTitle();
	abstract protected Rectangle getLocation();
	abstract protected void frameClosed();
	
}
